﻿@page "/SysOrder/Details/{id}"
@using SelfService.Model.Models
@using SelfService.ViewModel.SysOrderVMs
@inherits BasePage

<ValidateForm @ref="vform" Model="@Model" >
    <Row ItemsPerRow="ItemsPerRow.Two" RowType="RowType.Normal">
        <Display @bind-Value="@Model.Entity.ID"   ShowLabel="true"/>
        <Display @bind-Value="@Model.Entity.CardNo" ShowLabel="true"/>
        <Display @bind-Value="@Model.Entity.Code" ShowLabel="true"/>
        <Display @bind-Value="@Model.Entity.TradeNo" ShowLabel="true"/>
        <Display @bind-Value="@Model.Entity.Department" ShowLabel="true"/>
        <Display @bind-Value="@Model.Entity.Doctor" ShowLabel="true"/>
        <Display @bind-Value="@Model.Entity.Amount"  ShowLabel="true"/>
        <Textarea rows="4" @bind-Value="@Model.Entity.RawData" IsDisabled="true" ShowLabel="true" ></Textarea>
        <Textarea rows="4" @bind-Value="@Model.Entity.ErrorMessage" IsDisabled="true" ShowLabel="true" ></Textarea>
        <Display @bind-Value="@Model.Entity.Status"   ShowLabel="true"/>
        <Display @bind-Value="@Model.Entity.SocialSecurityStatus"   ShowLabel="true"/>
        @if (Model.Entity.SocialSecurityStatus == SocialSecurityType.预结算 || Model.Entity.SocialSecurityStatus == SocialSecurityType.冲正失败)
        {
            <Button Color="Color.Warning" Icon="fa fa-save" Text="冲正" OnClick="OnResver"></Button>
        }
    </Row>
    <div class="modal-footer table-modal-footer">
        <Button Color="Color.Primary" Icon="fa fa-save" Text="@WtmBlazor.Localizer["Sys.Close"]" OnClick="OnClose"></Button>
    </div>
</ValidateForm>

@code {
    private SysOrderVM Model = null;
    private ValidateForm vform { get; set; }
    [Parameter]
    public string id { get; set; }
    
    protected override async Task OnInitializedAsync()
    {
        var rv = await WtmBlazor.Api.CallAPI<SysOrderVM>($"/api/SysPrescription/{id}");
        Model = rv.Data;
    }

    private async Task OnResver()
    {
        var rv = await WtmBlazor.Api.CallAPI<Result<SysPrescription>>($"/api/SysSocialSecurity/Reverse?prescriptionId={id}");
        if (rv.Data?.Code == 200)
        {
            await WtmBlazor.Toast.Success("成功", $"冲正成功");
        }
        else
        {
            await WtmBlazor.Toast.Error("错误", $"冲正失败{rv.Data?.Message}");
        }
    }
    
    private void OnClose()
    {
        CloseDialog();
    }
}
